package cn.study.luckyapp.server;

import cn.study.luckyapp.activity.command.ActivityAddCmdExe;
import cn.study.luckyapp.activity.command.ActivityUpdateCmdExe;
import cn.study.luckyapp.activity.command.DrawCmdExe;
import cn.study.luckyapp.activity.query.ActivityListByParamQueryExe;
import cn.study.luckyclient.api.IActivityService;
import cn.study.luckyclient.dto.ActivityAddCmd;
import cn.study.luckyclient.dto.ActivityUpdateCmd;
import cn.study.luckyclient.dto.data.ActivityVo;
import cn.study.luckyclient.dto.data.DrawResultVo;
import cn.study.luckyclient.dto.query.ActivityListByParamQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@AllArgsConstructor
@Service
public class ActivityServiceImpl implements IActivityService {
    private final ActivityAddCmdExe activityAddCmdExe;
    private final ActivityUpdateCmdExe activityUpdateCmdExe;
    private final ActivityListByParamQueryExe activityListByParamQueryExe;
    private final DrawCmdExe drawCmdExe;
    @Override
    public ActivityVo add(ActivityAddCmd cmd) {
       return activityAddCmdExe.execute(cmd);
    }

    @Override
    public ActivityVo update(ActivityUpdateCmd cmd) {
        return activityUpdateCmdExe.execute(cmd);
    }

    @Override
    public IPage<ActivityVo> page(ActivityListByParamQuery query) {
        return activityListByParamQueryExe.execute(query);
    }

    @Override
    public ActivityVo one(Long id) {
        ActivityListByParamQuery activityListByParamQuery = new ActivityListByParamQuery();
        activityListByParamQuery.setId(id);
        IPage<ActivityVo> execute = activityListByParamQueryExe.execute(activityListByParamQuery);
        return execute.getRecords().get(0);
    }

    @Override
    public DrawResultVo draw(Long activityId, Long userId) {
        return drawCmdExe.execute(activityId,userId);
    }
}
